package com.community.contents;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.community.contents.dto.TopicDTO;
import com.community.contents.entity.PostEntity;
import com.community.contents.entity.TopicEntity;
import com.community.contents.service.IPostService;
import com.community.contents.service.ITopicService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.kafka.core.KafkaTemplate;

import java.util.List;

@SpringBootTest
class TopicTest1 {

    @Autowired
    private ITopicService topicService;

    @Autowired
    private IPostService postService;

    @Autowired
    private KafkaTemplate kafkaTemplate;

    @Test
    public void testPostToKafka() {
        List<PostEntity> list = postService.list();
        for (PostEntity postEntity : list) {
            String jsonString = JSON.toJSONString(postEntity);
            kafkaTemplate.send("post-index", jsonString);
        }
    }

    @Test
    void contextLoads() {
        Page<TopicDTO> page = new Page<>();
        List<TopicEntity> list = topicService.list();
        System.out.println(list);
    }

}
